package com.eqdd.yiqidian.ui.discover.workcircle;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.WorkCircleInfoActivityCustom;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.WorkCircleBean;
import com.eqdd.yiqidian.bean.rebuild.CommentResultBean;
import com.eqdd.yiqidian.bean.rebuild.HttpResultRows;
import com.eqdd.yiqidian.box.ItemDecoration.SectionDividerItemDecoration;
import com.eqdd.yiqidian.box.span.NoLineClickSpan;
import com.eqdd.yiqidian.helper.mvchelper.ModelRx2DataSource;
import com.eqdd.yiqidian.helper.mvchelper.Rx2DataSource;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.http.JsonCallBack;
import com.eqdd.yiqidian.http.JsonConverter;
import com.eqdd.yiqidian.ui.InputDialogActivity;
import com.eqdd.yiqidian.ui.companyspace.ProductInfoActivity;
import com.eqdd.yiqidian.ui.mine.UserCardActivity;
import com.eqdd.yiqidian.ui.yiqiyue.ArticleInfoActivity;
import com.eqdd.yiqidian.utils.CopyUtil;
import com.eqdd.yiqidian.utils.DensityUtil;
import com.eqdd.yiqidian.utils.DialogUtil;
import com.eqdd.yiqidian.utils.HttpUtil;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.ActionSheetDialog;
import com.eqdd.yiqidian.widget.InputDialogFragment;
import com.jakewharton.rxbinding.view.RxView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.shizhefei.mvc.MVCCoolHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.reactivex.Flowable;
import io.rong.imkit.utils.RongDateUtils;

public class WorkCircleInfoActivity extends BaseActivity {
    private WorkCircleInfoActivityCustom dataBinding;
    private WorkCircleBean workBean;
    private SlimAdapterEx slimAdapterExHead;
    private SlimAdapterEx slimAdapterExImg;
    private InputDialogFragment inputDialogFragment;
    private MVCCoolHelper<List<CommentResultBean>> mvcHelper;
    private ModelRx2DataSource<CommentResultBean> dataSource;
    private SlimAdapterEx<CommentResultBean> slimAdapterEx;
    private SimpleDateFormat sf;
    private AlertDialog deleteArticle;
    private ActionSheetDialog alertView;
    private AlertDialog deleteComment;
    private ActionSheetDialog alertViewDelete;
    private int clickedPos;
    private String replyTo;
    private int replyToCommentId;
    private String createId;
    private int pageNum;
    private String talkTo;
    private String parentUserGuid;
    private int firstCommentId;
    private SlimAdapterEx slimTalkAdapter;
    private boolean isCommentUp;
    private int dealPos;
    private boolean isMyComment;
    private int commentId;
    private String talkContent;
    private int type;
    private MaterialDialog moreDialog;
    private int id;
    private int displayType;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        isKeyBoardJustPan = false;
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_work_circle_info);
        initTopTitleBar(View.VISIBLE, "详情");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Config.INPUT && resultCode == Config.SUCCESS) {
            String content = data.getStringExtra(Config.CONTENT);
            HttpUtil.commentWorkCircle(WorkCircleInfoActivity.this, id, parentId, content, parentUserGuid, firstCommentId, (commentBean) -> {
                if (slimTalkAdapter == null) {
                    slimAdapterEx.getData().add(0, (CommentResultBean) commentBean);
                    slimAdapterEx.notifyItemInserted(0);
                } else if (isCommentUp) {
                    slimTalkAdapter.getData().add(0, (CommentResultBean) commentBean);
                    slimTalkAdapter.notifyItemInserted(0);
                } else {
                    slimTalkAdapter.getData().add((CommentResultBean) commentBean);
                    slimTalkAdapter.notifyItemInserted(slimTalkAdapter.getData().size() - 1);
                }
            });
        }
    }


    @Override
    public void initData() {
        if (slimAdapterExImg == null) {
//            initInputDialog();
            sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            id = getIntent().getIntExtra(Config.ID, 0);

            if (slimAdapterEx == null) {
                setRecyclerViewMoveFast(new LinearLayoutManager(this), dataBinding.recyclerViewComment);
                slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_36, new SlimInjector<CommentResultBean>() {
                    @Override
                    public void onInject(CommentResultBean data, IViewInjector injector) {
                        try {
                            List<CommentResultBean> commentResultBeen;
                            if (data.getList() != null) {
                                commentResultBeen = data.getList();
                            } else {
                                commentResultBeen = new ArrayList<>();
                            }
                            RecyclerView recyclerView = (RecyclerView) injector.findViewById(R.id.recyclerViewCommentComment);

                            recyclerView.setLayoutManager(new LinearLayoutManager(WorkCircleInfoActivity.this));
                            SlimAdapterEx<CommentResultBean> slimAdapterExCommentChild = SlimAdapterEx.create().register(R.layout.list_item_37, new SlimInjector<CommentResultBean>() {
                                @Override
                                public void onInject(CommentResultBean data, IViewInjector injector) {
                                    injector.with(R.id.tv_comment_comment, view -> {
                                        TextView textView = (TextView) view;
                                        SpannableString spStr = new SpannableString(data.getStaffName() + ":" + " @" + data.getParentStaffName() + " " + data.getMessage());
                                        NoLineClickSpan firstSpan = new NoLineClickSpan("#3423ff", v -> {

                                            Bundle bundle = new Bundle();
                                            bundle.putString(Config.GUID, data.getCreater());
                                            startActivity(UserCardActivity.class, bundle);
                                        });
                                        NoLineClickSpan secondSpan = new NoLineClickSpan("#3423ff", v -> {
                                            Bundle bundle = new Bundle();
                                            bundle.putString(Config.GUID, data.getParentUserGuid());
                                            startActivity(UserCardActivity.class, bundle);
                                        });
                                        spStr.setSpan(firstSpan, 0, data.getStaffName().length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                                        spStr.setSpan(secondSpan, spStr.toString().indexOf("@"), spStr.toString().indexOf("@") + 1 + data.getParentStaffName().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                        textView.setMovementMethod(LinkMovementMethod.getInstance());
                                        textView.setText(spStr);
                                    });
                                }
                            }).attachTo(recyclerView).updateData(commentResultBeen);
                            ItemClickSupport.addTo(recyclerView)
                                    .setOnItemClickListener((recyclerView1, position, v) -> {
                                        CommentResultBean dataItem = slimAdapterExCommentChild.getDataItem(position);
                                        isMyComment = dataItem.getCreater().equals(AppConstent.user.getGuid());
                                        parentId = dataItem.getId();
                                        parentUserGuid = dataItem.getCreater();
                                        firstCommentId = data.getId();
                                        commentId = dataItem.getId();
                                        talkTo = dataItem.getStaffName();
                                        talkContent = dataItem.getMessage();
                                        type = 2;
                                        slimTalkAdapter = slimAdapterExCommentChild;
                                        isCommentUp = false;
                                        dealPos = position;
                                        showMoreDialog();
                                    });

                            injector.with(R.id.iv_comment_head, v -> ImageUtil.setCircleImage(data.getIphoto(), (ImageView) v))
                                    .text(R.id.tv_comment_up_left, data.getStaffName())
                                    .text(R.id.tv_comment_down_right, RongDateUtils.getConversationFormatDate(sf.parse(data.getCreateTime()).getTime(), WorkCircleInfoActivity.this))
                                    .text(R.id.tv_comment_down_left, data.getDepartName() + " " + data.getPostName())
                                    .text(R.id.tv_comment, data.getMessage())
                                    .visibility(R.id.tv_more_comment, data.getCommentCount() > 3 ? View.VISIBLE : View.GONE)
                                    .text(R.id.tv_more_comment, String.format("展开更多%d条评论", data.getCommentCount()))
                                    .clicked(R.id.tv_more_comment, v -> {

                                        Bundle bundle = new Bundle();
                                        bundle.putSerializable(Config.BEAN, data);
                                        bundle.putInt(Config.ID, id);
                                        startActivity(WorkCircleCommentActivity.class, bundle);
                                    })
                                    .clicked(R.id.iv_comment_comment, v -> {
                                        parentId = data.getId();
                                        talkTo = data.getStaffName();
                                        parentUserGuid = data.getCreater();
                                        firstCommentId = data.getId();
                                        slimTalkAdapter = slimAdapterExCommentChild;
                                        isCommentUp = true;
                                        dealPos = slimAdapterEx.getData().indexOf(data);
                                        talkTo();
                                    })
                                    .clicked(R.id.tv_comment, v -> {
                                        isMyComment = data.getCreater().equals(AppConstent.user.getGuid());
                                        parentId = data.getId();
                                        parentUserGuid = data.getCreater();
                                        firstCommentId = data.getId();
                                        commentId = data.getId();
                                        talkTo = data.getStaffName();
                                        talkContent = data.getMessage();
                                        type = 1;
                                        slimTalkAdapter = slimAdapterExCommentChild;
                                        isCommentUp = true;
                                        dealPos = slimAdapterEx.getData().indexOf(data);
                                        showMoreDialog();
                                    })
                                    .clicked(R.id.iv_comment_head, view -> {
                                        Bundle bundle = new Bundle();
                                        bundle.putString(Config.GUID, data.getCreater());
                                        startActivity(UserCardActivity.class, bundle);
                                    });

                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }).attachTo(dataBinding.recyclerViewComment);
            }
            RxView.clicks(dataBinding.llHeadImg)
                    .subscribe((v) -> {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", id + "");
                        bundle.putString("idName", "workCircleId");
                        startActivity(ZanListActivity.class, bundle);
                    });
            RxView.clicks(dataBinding.ivOption)
                    .subscribe((v) -> {
                        if (deleteArticle == null) {
                            deleteArticle = DialogUtil.tip(WorkCircleInfoActivity.this, "确认要删除该说说吗？", () -> {
                                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.DELETE_WORK_CIRCLE_INFO)
                                        .params("workCircleId", id)
                                        .params("userGuid", user.getGuid())
                                        .execute(new DialogCallBack<HttpResult>(WorkCircleInfoActivity.this) {
                                            @Override
                                            public void onSuccess(Response<HttpResult> response) {
                                                HttpResult httpResult = response.body();
                                                ToastUtil.showShort(httpResult.getMsg());
                                                if (httpResult.getStatus() == 200) {
                                                    setResult(Config.DELETE);
                                                    finish();
                                                }
                                            }
                                        });
                            });
                        }
                        deleteArticle.show();
                    });
            mvcHelper = new MVCCoolHelper<>(dataBinding.coolRefreshView);
            dataSource = new ModelRx2DataSource<>(new ModelRx2DataSource.OnLoadSource() {
                @Override
                public Flowable<List> loadSource(int page, Rx2DataSource.DoneActionRegister register) {
                    if (page == 1) {
                        setView();
                    }
                    pageNum = page == 1 ? 0 : pageNum;

                    return OkGo.<HttpResultRows<CommentResultBean>>post(HttpConfig.BASE_URL + HttpConfig.WORK_CIRCLE_COMMENT_LIST_NEW)
                            .params("workcircleId", id)
                            .params("page", pageNum)
                            .converter(new JsonConverter<HttpResultRows<CommentResultBean>>() {
                                @Override
                                public void test() {
                                    super.test();
                                }
                            })
                            .adapt(new FlowableBody<>())
                            .flatMap(listHttpResult -> {
                                pageNum = listHttpResult.getItems().getPage();
                                if (listHttpResult.getStatus() == 200) {
                                    return Flowable.just(listHttpResult.getItems() == null ? new ArrayList<CommentResultBean>() : listHttpResult.getItems().getRows());
                                } else {
                                    ToastUtil.showShort(listHttpResult.getMsg());
                                    return Flowable.just(new ArrayList<>());
                                }
                            });
                }
            }, 10);
            dataBinding.rlHeadRoot.removeViewAt(0);
            slimAdapterEx.addHeader(dataBinding.nestedScrollView);
            slimAdapterEx.updateData(new ArrayList());
            mvcHelper.setDataSource(dataSource);
            mvcHelper.setAdapter(slimAdapterEx);
            mvcHelper.refresh();
        }
    }

    private void showMoreDialog() {
        if (moreDialog == null) {
            ArrayList<Object> objects = new ArrayList<>();
            objects.add("回复");
            objects.add("复制");
            objects.add("删除");
            SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().registerDefault(R.layout.list_item_54, new SlimInjector() {
                @Override
                public void onInject(Object data, IViewInjector injector) {

                    injector.text(R.id.tv_content, (String) data);
                }
            }).updateData(objects);
            moreDialog = new MaterialDialog.Builder(this)
                    .adapter(slimAdapterEx, new LinearLayoutManager(this))
                    .build();
            moreDialog.getRecyclerView().addItemDecoration(new SectionDividerItemDecoration(this)
                    .setHeadHeight(0)
                    .setRightPadding(DensityUtil.percentW(40))
                    .setLeftPadding(DensityUtil.percentW(40))
                    .setLastBootomHeght(0));
            ItemClickSupport.addTo(moreDialog.getRecyclerView())
                    .setOnItemClickListener((recyclerView, position, v) -> {
                        switch (position) {
                            case 0:
                                talkTo();
                                break;
                            case 1:
                                CopyUtil.copy(talkContent);
                                break;
                            case 2:
                                HttpUtil.deleteWorkCircleComment(WorkCircleInfoActivity.this, commentId, id, type, () -> {
                                    if (isCommentUp) {
                                        slimAdapterEx.getData().remove(dealPos);
                                        slimAdapterEx.notifyItemRemoved(dealPos);
                                    } else {
                                        slimTalkAdapter.getData().remove(dealPos);
                                        slimTalkAdapter.notifyItemRemoved(dealPos);
                                    }
                                });
                                break;
                        }
                        moreDialog.dismiss();
                    });
        }
        SlimAdapterEx slimAdapterExMore = (SlimAdapterEx) moreDialog.getRecyclerView().getAdapter();
        if (isMyComment && slimAdapterExMore.getData().size() == 2) {
            slimAdapterExMore.getData().add("删除");
            slimAdapterExMore.notifyItemInserted(2);
        } else if (!isMyComment && slimAdapterExMore.getData().size() == 3) {
            slimAdapterExMore.getData().remove(2);
            slimAdapterExMore.notifyItemRemoved(2);
        }
        moreDialog.show();

    }

    private void talkTo() {
        Bundle bundle = new Bundle();
        bundle.putString(Config.TALK_TO, talkTo);
        startActivityForResult(InputDialogActivity.class, bundle, Config.INPUT);
    }

    private void zan() {
        OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.WORK_CIRCLE_ZAN)
                .params("companyId", user.getCompanyId())
                .params("userGuid", user.getGuid())
                .params("workCircleId", id)
                .execute(new JsonCallBack<HttpResult>() {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                        }
                    }
                });

        isChange = true;
        dataBinding.stvSupport.setText((workBean.getZanCount() + 1) + "");
        dataBinding.stvSupport.setDrawable(getResources().getDrawable(R.mipmap.ic_heart_red));
        workBean.setZanCount(workBean.getZanCount() + 1);
        workBean.setIsZan(true);
        dataBinding.stvSupport.setEnabled(false);
        workBean.getUserZan().add(0, new WorkCircleBean.UserZanBean(user.getGuid(), user.getIphoto()));
        slimAdapterExHead.updateData(workBean.getUserZan().subList(0, workBean.getUserZan().size() > 3 ? 3 : workBean.getUserZan().size()));
    }

    private void updateView() {
        ImageUtil.setCircleImage(workBean.getIphoto(), dataBinding.ivHead);
        dataBinding.tvCity.setText(workBean.getLocation());
        dataBinding.tvCity.setVisibility(TextUtils.isEmpty(workBean.getLocation()) ? View.GONE : View.VISIBLE);
        try {
            dataBinding.tvTime.setText(RongDateUtils.getConversationListFormatDate(sf.parse(workBean.getCreateTime()).getTime(), this));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        dataBinding.ivOption.setVisibility(user.getGuid().equals(workBean.getCreater()) ? View.VISIBLE : View.GONE);
        dataBinding.stvName.setText(workBean.getStaffName());
        dataBinding.tvContent.setText(workBean.getMessage());
        dataBinding.stvSupport.setText(workBean.getZanCount() + "");
        dataBinding.stvSupport.setDrawable(getResources().getDrawable(workBean.isIsZan() ? R.mipmap.ic_heart_red : R.mipmap.ic_heart_hint));
        dataBinding.stvMsg.setText(workBean.getCommentCount() + "");
        dataBinding.stvMsg.setDrawable(getResources().getDrawable(R.mipmap.ic_comment));
        if (slimAdapterExImg != null)
            slimAdapterExImg.updateData(workBean.getNewImages());
        dataBinding.stvSupport.setEnabled(!workBean.isIsZan());
        slimAdapterExHead.updateData(workBean.getUserZan().
                subList(0, workBean.getUserZan().size() > 3 ? 3 : workBean.getUserZan().size()));
    }

    private void setRecyclerViewMoveFast(RecyclerView.LayoutManager layoutManager, RecyclerView recyclerView) {
        recyclerView.setLayoutManager(layoutManager);
        layoutManager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void onBackPressed() {

        if (dataBinding.vImageWatcher.isShown()) {
            dataBinding.vImageWatcher.onSingleTapConfirmed();
        } else {
            if (isChange) {
                Intent intent = new Intent();
                intent.putExtra("bean", workBean);
                setResult(Config.CHANGE, intent);
            }
            super.onBackPressed();
        }
    }

    @Override
    public void setView() {
        OkGo.<HttpResult<WorkCircleBean>>post(HttpConfig.BASE_URL + HttpConfig.WORK_CIRCLE_INFO)
                .params("workCircleId", id)
                .params("userGuid", user.getGuid())
                .execute(new DialogCallBack<HttpResult<WorkCircleBean>>(WorkCircleInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult<WorkCircleBean>> response) {
                        HttpResult<WorkCircleBean> httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                            workBean = httpResult.getItems();
                            initView();
                            updateView();
                        }
                    }
                });
    }

    private void initView() {
        int displayType = getIntent().getIntExtra("type", 0);
        if (displayType == 0) {
            dataBinding.recyclerViewImg.setVisibility(View.VISIBLE);
            setRecyclerViewMoveFast(new LinearLayoutManager(this), dataBinding.recyclerViewImg);
            dataBinding.recyclerViewImg.setLayoutManager(new GridLayoutManager(this, 3));
            ImageView[] imageViews = new ImageView[workBean.getNewImages() == null ? 0 : workBean.getNewImages().size()];
            slimAdapterExImg = SlimAdapterEx.create().register(R.layout.list_item_full_img, new SlimInjector<String>() {
                @Override
                public void onInject(String data, IViewInjector injector) {
                    imageViews[workBean.getNewImages().indexOf(data)] = (ImageView) injector.findViewById(R.id.iv_img);
                    injector.with(R.id.iv_img, v -> {
                        ImageUtil.setImage(data, (ImageView) v);
                    }).clicked(R.id.iv_img, v -> {
                        dataBinding.vImageWatcher.setBackgroundColor(Color.parseColor("#000000"));
                        dataBinding.vImageWatcher.show((ImageView) v, Arrays.asList(imageViews), workBean.getNewImages());
                    });
                }
            }).attachTo(dataBinding.recyclerViewImg);
        } else if (displayType == 1) {
            String imgUrl = null;
            if (workBean.getNewImages() != null && workBean.getNewImages().size() > 0) {
                imgUrl = workBean.getNewImages().get(0);
            }
            dataBinding.layoutLink.setVisibility(View.VISIBLE);
            RequestOptions options = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.drawable.insert_link)
                    .error(R.drawable.insert_link);
            Glide.with(this)
                    .load(imgUrl != null ? imgUrl : R.drawable.insert_link)
                    .apply(options)
                    .into(dataBinding.ivLinkImage);
            dataBinding.tvLinkText.setText(workBean.getSourceTitle());
            dataBinding.layoutLink.setOnClickListener(v -> {
                if ("易企阅".equals(workBean.getSource())) {
                    String s = workBean.getSourceUrl().substring(workBean.getSourceUrl().lastIndexOf("=") + 1, workBean.getSourceUrl().length());
                    Intent intent = new Intent(WorkCircleInfoActivity.this, ArticleInfoActivity.class);
                    intent.putExtra("id", Integer.parseInt(s));
                    startActivity(intent);
                } else if ("工作圈".equals(workBean.getSource())) {
                    String s = workBean.getSourceUrl().substring(workBean.getSourceUrl().indexOf("=") + 1, workBean.getSourceUrl().indexOf("&"));
                    //String s = workBean.getSourceUrl().substring(workBean.getSourceUrl().lastIndexOf("=") + 1, workBean.getSourceUrl().length());
                    Intent intent = new Intent(WorkCircleInfoActivity.this, WorkCircleInfoActivity.class);
                    intent.putExtra("id", Integer.valueOf(s));
                    startActivity(intent);
                } else if ("产品信息".equals(workBean.getSource())) {
                    String s = workBean.getSourceUrl().substring(workBean.getSourceUrl().lastIndexOf("=") + 1, workBean.getSourceUrl().length());
                    Intent intent = new Intent(WorkCircleInfoActivity.this, ProductInfoActivity.class);
                    intent.putExtra(Config.ID, Integer.parseInt(s));
                    startActivity(intent);
                }
            });

        }

        RxView.clicks(dataBinding.stvSupport).subscribe(v -> zan());
        if (slimAdapterExHead == null) {
            setRecyclerViewMoveFast(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false), dataBinding.recyclerViewHead);
            slimAdapterExHead = SlimAdapterEx.create().register(R.layout.list_item_head_img, new SlimInjector<WorkCircleBean.UserZanBean>() {
                @Override
                public void onInject(WorkCircleBean.UserZanBean workBean, IViewInjector injector) {
                    injector.with(R.id.iv_head_img, v -> ImageUtil.setCircleImage(workBean.getHeadImage(), (ImageView) v));
                }
            }).attachTo(dataBinding.recyclerViewHead);
        }
        ItemClickSupport.addTo(dataBinding.recyclerViewHead)
                .setOnItemClickListener((recyclerView, position, v) -> {
                    Bundle bundle = new Bundle();
                    bundle.putString("id", id + "");
                    bundle.putString("idName", "workCircleId");
                    startActivity(ZanListActivity.class, bundle);
                });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_msg:
                parentId = 0;
                firstCommentId = 0;
                parentUserGuid = "";
                talkTo = workBean.getStaffName();
                slimTalkAdapter = null;
                talkTo();
                break;
        }
    }

    private int parentId = 0;
    private boolean isChange = false;
}
